package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchDept;
import com.ruoyi.teach.service.ISchDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学校院系Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/dept")
public class SchDeptController extends BaseController
{
    @Autowired
    private ISchDeptService schDeptService;

    /**
     * 查询学校院系列表
     */
    @PreAuthorize("@ss.hasPermi('teach:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchDept schDept)
    {
        startPage();
        List<SchDept> list = schDeptService.selectSchDeptList(schDept);
        return getDataTable(list);
    }

    /**
     * 导出学校院系列表
     */
    @PreAuthorize("@ss.hasPermi('teach:dept:export')")
    @Log(title = "学校院系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchDept schDept)
    {
        List<SchDept> list = schDeptService.selectSchDeptList(schDept);
        ExcelUtil<SchDept> util = new ExcelUtil<SchDept>(SchDept.class);
        util.exportExcel(response, list, "学校院系数据");
    }

    /**
     * 获取学校院系详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:dept:query')")
    @GetMapping(value = "/{dId}")
    public AjaxResult getInfo(@PathVariable("dId") Long dId)
    {
        return AjaxResult.success(schDeptService.selectSchDeptByDId(dId));
    }

    /**
     * 新增学校院系
     */
    @PreAuthorize("@ss.hasPermi('teach:dept:add')")
    @Log(title = "学校院系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchDept schDept)
    {
        return toAjax(schDeptService.insertSchDept(schDept));
    }

    /**
     * 修改学校院系
     */
    @PreAuthorize("@ss.hasPermi('teach:dept:edit')")
    @Log(title = "学校院系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchDept schDept)
    {
        return toAjax(schDeptService.updateSchDept(schDept));
    }

    /**
     * 删除学校院系
     */
    @PreAuthorize("@ss.hasPermi('teach:dept:remove')")
    @Log(title = "学校院系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dIds}")
    public AjaxResult remove(@PathVariable Long[] dIds)
    {
        return toAjax(schDeptService.deleteSchDeptByDIds(dIds));
    }
}
